
clear
do "...\First.do"
********************************************************************************
use "$work\analysis_sample.dta"

keep if inrange(age,40,70)

g help=1 if inrange(timing,-4,0)
bys pnr: egen N_pre_2=total(help)
tab N_pre_2

keep if N_pre_2==5
g gp_ndk=(mean_dk!=1)
g gp_male=(mean_male>0)
g gp_old=(mean_age>50)
g old=(age>60 & age!=.)



********************************************************************************
* TABLE 1
********************************************************************************

global gp_X "mean_age mean_male mean_dk ku au sdu other i.N_doctors"
global patient_X "male i.age non_dk married"

estimates clear
cap drop treatment
g treatment=low_ses
qui eststo, title("Low-SES"): reg yder_ses_max treatment $patient_X $gp_X if timing==1, cluster(newgpyr)

global gp_X "mean_age mean_dk ku au sdu other i.N_doctors yder_ses_max"
global patient_X "i.age non_dk married low_ses"

drop treatment
g treatment=male
qui eststo, title("Male"): reg gp_male treatment $patient_X  $gp_X ///
if timing==1, cluster(newgpyr)

global gp_X "mean_male mean_age ku au sdu other i.N_doctors yder_ses_max"
global patient_X "i.age male married low_ses"

drop treatment
g treatment=(non_dk==1)
qui eststo, title("Non-etnic Danish"): reg gp_ndk treatment $patient_X  $gp_X ///
 if timing==1, cluster(newgpyr)


global gp_X "mean_male mean_dk ku au sdu other i.N_doctors yder_ses_max"
global patient_X "non_dk male married low_ses"
 
drop treatment
g treatment=old
qui eststo, title("Age"): reg gp_old treatment $patient_X  $gp_X ///
if timing==1 & sample==1,  cluster(newgpyr)

esttab using "$table\fe_test_pcpcontrols_2302.tex", tex b(5) se label replace mtitle star(* 0.10 ** 0.05 *** 0.01) keep(treatment)

********************************************************************************
* Table D2 - GP x patient relationship
********************************************************************************

bys pnr ydernr: g N_years=_N


* New PCP controls
global gp_X "mean_age mean_male mean_dk solo ku au sdu other i.N_doctors"
global patient_X "male i.age non_dk married"

estimates clear
cap drop treatment
cap drop gp_treatment
g treatment=low_ses
g gp_treatment=yder_ses_max
qui eststo, title("Low-SES"): reg N_years treatment##gp_treatment $gp_X $patient_X ///
if timing==1, cluster(newgpyr) 

global gp_X "mean_age mean_dk solo ku au sdu other i.N_doctors yder_ses_max"
global patient_X "i.age non_dk married low_ses"

cap drop treatment
cap drop gp_treatment
g treatment=male
g gp_treatment=gp_male
qui eststo, title("Male"): reg N_years treatment##gp_treatment $gp_X $patient_X ///
if timing==1, cluster(newgpyr) 

global gp_X "mean_male mean_age solo ku au sdu other i.N_doctors yder_ses_max"
global patient_X "i.age male married low_ses"


cap drop treatment
cap drop gp_treatment
g treatment=non_dk
g gp_treatment=gp_ndk
qui eststo, title("Non-etnic Danish"): reg N_years treatment##gp_treatment $gp_X $patient_X ///
if timing==1, cluster(newgpyr)

global gp_X "mean_male mean_dk solo ku au sdu other i.N_doctors yder_ses_max"
global patient_X "non_dk male married low_ses"
 
cap drop treatment
cap drop gp_treatment
g treatment=old
g gp_treatment=gp_old
qui eststo, title("Age"): reg N_years treatment##gp_treatment $gp_X $patient_X ///
if timing==1, cluster(newgpyr) 

esttab using "$table\fe_N_years_pcpcontrols_23.tex", tex b(5) se label replace mtitle star(* 0.10 ** 0.05 *** 0.01) keep(1.treatment 1.gp_treatment 1.treatment#1.gp_treatment)









